home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14473 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  64 lines

  1. Newsgroups: comp.lang.c
  2. Path: new-news.sprintlink.net!eskimo!news
  3. From: mag@eskimo.com (mAg)
  4. Subject: Re: A quick newbie question...hopefully...HELP!
  5. X-Nntp-Posting-Host: tia1.eskimo.com
  6. Message-ID: <Dpw2qA.M2n@eskimo.com>
  7. Sender: news@eskimo.com (News User Id)
  8. Organization: *.*
  9. X-Newsreader: WinVN 0.93.10
  10. References: <4kn8gk$6t1@info.evansville.net>
  11. Date: Mon, 15 Apr 1996 05:46:57 GMT
  12.  
  13. In article <4kn8gk$6t1@info.evansville.net> (Sat, 13 Apr 1996 03:58:36 GMT), 
  14. gilligan@evansville.net says :
  15. >
  16. >Hi!
  17. >        I am just starting at C, and have a question...one of my problems is I
  18. >have to create a type of "Word Processor" where, regardless of number
  19. >of carriage returns or spaces, I have to cram as many words as
  20. >possible onto one line, be it 65 spaces or 40 (whatever the number),
  21. >but there must be one space in between each word, and the line cannot
  22. >end in the middle of the word.  The user is done when he/she hits
  23. >CONTROL-Z, and then everything that he/she has typed is reformatted to
  24. >as many lines as needed.  So, in other words, in this program, one
  25. >could type:
  26. >***********************************************************************************
  27. ******
  28. >THE DOG WENT
  29. >TO THE VET'S PLACE AND                 THEN REALIZED THAT
  30. >HE
  31. >WAS GETTING
  32. >A                     SHOT IN THE BUTT.
  33. >*****************************************************************************
  34. >And then when they hit Control-Z, it should read like this:
  35. >THE DOG WENT TO THE VET'S PLACE AND THEN REALIZED THAT HE WAS GETTING
  36. >A SHOT IN THE BUTT.
  37. >So you see how it is like a word processor, kind of.  Now, my thoughts
  38. >were either to use GETCHAR, or just get a string at a time, but I am a
  39. >bit confused on this latter part...any ideas would be GREATLY
  40. >appreciated...due to the fact that I don't get back here much, please
  41. >send all questions/comments/suggestions to:
  42. >gilligan@evansville.net
  43. >
  44. >And MANY thanks in return!!
  45. >Gilligan
  46. >
  47.  
  48. I would say, a good way to do it is :
  49.  
  50. read in all the text as one string using fgets(stdin,...) and use sscanf() to break 
  51. it into words and append a space to every word.
  52.  
  53.  
  54. -- 
  55. /* --------------------------------------------------------
  56.                       MAG@ESKIMO.COM
  57. http://www.eskimo.com/~mag/index.html
  58. ***********************************************************
  59. To understand recursion one must first understand recursion
  60. ***********************************************************
  61. -------------------------------------------------------- */
  62.  
  63.